package cn.lingxue.lingapi.config;

import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * [Sa-Token 权限认证] 配置类
 */
@Configuration
public class SaTokenConfigure {
    /**
     * 注册 [Sa-Token全局过滤器]
     */
    @Bean
    public FilterRegistrationBean<SaTokenFilter> getSaServletFilter() {
        FilterRegistrationBean<SaTokenFilter> registrationBean = new FilterRegistrationBean<>();
        registrationBean.setFilter(new SaTokenFilter());
        registrationBean.addUrlPatterns("/**"); // 匹配所有请求
        registrationBean.setOrder(1); // 设置过滤器的执行顺序，数值越小，优先级越高
        return registrationBean;
    }

}
